package com.sunxueqi.project.system.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sunxueqi.framework.annotation.Log;
import com.sunxueqi.framework.annotation.VLog;
import com.sunxueqi.framework.enums.BusinessType;
import com.sunxueqi.framework.web.controller.BaseController;
import com.sunxueqi.framework.web.vo.ResponseData;
import com.sunxueqi.project.system.service.IRoleService;
import com.sunxueqi.project.system.vo.Role;
import com.sunxueqi.project.system.vo.User;

import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api;

@Api(tags="角色")
@RestController
@RequestMapping("/system/role")
public class RoleController extends BaseController {

	@Autowired
	private IRoleService roleService;
	
	/**
	 * 获取角色列表
	 * @param role
	 * @return
	 */
	@GetMapping("/list")
	public ResponseData list(Role role) {
		startPage();
		List<Role> list = roleService.selectRoleList(role);
		return ResponseData.successTableData(list);
	}
	
	/**
	 * 新增角色
	 * @param role
	 * @return
	 */
	@PostMapping
	public ResponseData add(@RequestBody Role role) {
		return super.getResponseDataRow(roleService.addRole(role));
	}
	
	/**
	 * 修改角色
	 * @param role
	 * @return
	 */
	@PutMapping
	public ResponseData update(@RequestBody Role role) {
		return super.getResponseDataRow(roleService.updateRole(role));
	}
	
	/**
	 * 删除角色
	 * @param role
	 * @return
	 */
	@DeleteMapping("/{ids}")
	public ResponseData remove(@PathVariable String ids) {
		String [] idArray = StrUtil.split(ids, ",");
		return super.getResponseDataRow(roleService.deleteRoleByIds(idArray));
	}
	
	/**
	 * 修改角色状态
	 * @param role
	 * @return
	 */
	@Log(title = "角色状态修改", businessType = BusinessType.UPDATE)
	@PutMapping("/changeStatus")
	public ResponseData changeStatus(@RequestBody Role role) {
		return getResponseDataRow(roleService.changeStatus(role));
	}
}
